package com.xiaomi.result;

import lombok.Data;

import java.io.Serializable;

@Data
/**
 * 封装返回结果
 */
public class Result<T> implements Serializable {

    private int status; //编码：1成功，0和其它数字为失败
    private String msg; //错误信息
    private T data; //数据

    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<T>();
        result.status = 200;
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> success(String msg,T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.msg = msg;
        result.status = 200;
        return result;
    }

    public static <T> Result<T> error(int status, String msg) {
        Result result = new Result();
        result.msg = msg;
        result.status = status;
        return result;
    }

}